﻿using System;
using System.Collections.Generic;

namespace YArchitech.MEP
{
	public class HYDuct : HYTube
	{
		public HYDuct()
		{
			this.Name = "管段";
			base.Size = new HYTubeSize(HYTubeShape.Rectangular, 800.0, 320.0);
		}

		public bool AddTaper(HYDuctTaper taper)
		{
			if (this.m_tapers == null)
			{
				this.m_tapers = new SortedSet<HYDuctTaper>();
			}
			this.m_tapers.Add(taper);
			taper.Previous = this;
			taper.Place = HYComponent.Down(base.Place);
			return true;
		}

		public bool HasTaper
		{
			get
			{
				return this.m_tapers != null && this.m_tapers.Count > 0;
			}
		}

		public ICollection<HYDuctTaper> Tapers
		{
			get
			{
				return this.m_tapers;
			}
		}

		public override void AddToSystem(HYSystem hySystem)
		{
			base.AddToSystem(hySystem);
			if (this.HasTaper)
			{
				foreach (HYDuctTaper hyductTaper in this.m_tapers)
				{
					hyductTaper.AddToSystem(hySystem);
				}
			}
		}

		public override void RebuildIndex(ref int index)
		{
			base.RebuildIndex(ref index);
			if (this.HasTaper)
			{
				foreach (HYDuctTaper hyductTaper in this.m_tapers)
				{
					hyductTaper.RebuildIndex(ref index);
				}
			}
		}

		public override void ReAllocateFlow()
		{
			double num = 0.0;
			if (this.m_Next != null)
			{
				this.m_Next.ReAllocateFlow();
				num = this.m_Next.Flow;
			}
			double num2 = 0.0;
			if (this.HasTaper)
			{
				foreach (HYDuctTaper hyductTaper in this.m_tapers)
				{
					hyductTaper.ReAllocateFlow();
					num2 += hyductTaper.Flow;
				}
			}
			double num3 = num + num2;
			if (base.Flow < num3)
			{
				base.Flow = num3;
			}
		}

		public override void AllocateFlow()
		{
			double num = 0.0;
			if (this.m_Next != null)
			{
				this.m_Next.AllocateFlow();
				num = this.m_Next.Flow;
			}
			double num2 = 0.0;
			if (this.HasTaper)
			{
				foreach (HYDuctTaper hyductTaper in this.m_tapers)
				{
					hyductTaper.AllocateFlow();
					num2 += hyductTaper.Flow;
				}
			}
			base.Flow = num + num2;
		}

		public override void Cal(HYSystemOption option)
		{
			this.m_Roughness = option.Roughness;
			base.Cal(option);
		}

		protected override void CalCoefficient()
		{
			this.m_Coefficient = 0.0;
		}

		private SortedSet<HYDuctTaper> m_tapers;
	}
}
